package com.emser.unc.activitys.resources;

import java.util.ArrayList;
import java.util.List;

import com.emser.unc.R;
import com.emser.unc.serializable.SaleReportDTO;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;



public class SaleReportSentAdapter extends ArrayAdapter<SaleReportDTO> {
	
	private ArrayList<SaleReportDTO> entries;
	private Activity activity;
	
	public SaleReportSentAdapter(Activity a, int textViewResourceId,
			List<SaleReportDTO> values) {
		super(a, textViewResourceId, values);
		this.entries = (ArrayList<SaleReportDTO>) values;
		this.activity = a;
	}
	
	public static class ViewHolder {
		public TextView item0;
		public TextView item1;
		public TextView item2;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ViewHolder holder;
        if (v == null) {
            LayoutInflater vi =
                (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.r_sale_report_sent_row_view, null);
            holder = new ViewHolder();
            holder.item0 = (TextView) v.findViewById(R.id.customer_code);
            holder.item1 = (TextView) v.findViewById(R.id.products_type_quantity);
            holder.item2 = (TextView) v.findViewById(R.id.total_amount);
            v.setTag(holder);
        }
        else{
        	holder=(ViewHolder)v.getTag();
        }
        final SaleReportDTO report = entries.get(position);
        if (report != null) {
        	Integer productsTypeQuantity = report.getProductsSold().size();
        	holder.item0.setText(report.getCustomerID().toString());
            holder.item1.setText(productsTypeQuantity.toString());
            holder.item2.setText(report.getAmount().toString());
        }
        return v;
    }
	
	
}
